//
//  USMomentsController.m
//  us
//
//  Created by karry on 2025/6/2.
//

#import "USMomentsController.h"
#import "USMomentsAddController.h"
#import "USMomentsDetailController.h"
#import "USMomentsModel.h"
#import "USMomentsCell.h"
#import "USMomentCommentCell.h"
#import <MJRefresh/MJRefresh.h>
#import "USCommentInputToolView.h"
#import "USPhotoPreviewController.h"
@interface USMomentsController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray <USMomentsModel *>*list;
@property (nonatomic, assign) NSInteger currentPage;
@property (nonatomic, assign) NSInteger pageSize;
@property (nonatomic, assign) NSInteger type;//类型:1:共享空间全部心情日记;2:我的心情日记;3:她的心情日记
@property (nonatomic, assign) BOOL hasMore;

@property (nonatomic, strong) USMomentsModel* editModel;
@property (nonatomic, strong) USCommentInputToolView *commentTool;
@property (nonatomic, strong) NSIndexPath *commentIndexPath;
@end

@implementation USMomentsController


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    
    [self.commentTool.textField resignFirstResponder];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    
    // 注册键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupView];
     
    self.type = 1;

    [self setupRefresh];
    [self.us_tableView.mj_header beginRefreshing];
}

- (void)setupView{
    UIButton *titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [titleBtn setTitle:@"我们的日记" forState:0];
    [titleBtn setTitleColor:UIColor.labelColor forState:0];
    [titleBtn.titleLabel setFont:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium]];
    [titleBtn setImage:[UIImage imageNamed:@"arrow_down"] forState:0];
    titleBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
    [titleBtn addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = titleBtn;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"ic_add"] style:UIBarButtonItemStylePlain target:self action:@selector(addAction)];

    
    self.us_tableView.delegate = self;
    self.us_tableView.dataSource = self;
    self.us_tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    self.us_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.us_tableView.backgroundColor = UIColor.clearColor;
    self.us_tableView.rowHeight = UITableViewAutomaticDimension;
    self.us_tableView.estimatedRowHeight = 150;
    self.us_tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; // 滚动时自动收起键盘（可选）

    [self.us_tableView registerClass:[USMomentsCell class] forCellReuseIdentifier:@"USMomentsCell"];
    
    [self.us_tableView registerClass:[USMomentCommentCell class] forCellReuseIdentifier:@"USMomentCommentCell"];

    [self.view addSubview:self.commentTool];

}
- (void)keyboardWillShow:(NSNotification *)notification {

    NSDictionary *info = notification.userInfo;
    NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGRect kbFrame = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyboardHeight = kbFrame.size.height;
    
    CGFloat toolHeight = 74;
    [UIView animateWithDuration:duration animations:^{
        self.commentTool.frame = CGRectMake(0, self.view.bounds.size.height - keyboardHeight - toolHeight, self.view.bounds.size.width, toolHeight);
        self.commentTool.hidden = NO;
    }];
   
    //键盘弹出时，将 tableView 滑动到当前点击 cell 所在 section 的“最后一个 cell”底部，使其刚好显示在键盘上方。
    if (!self.commentIndexPath) return;


    NSInteger section = self.commentIndexPath.section;
    NSInteger rowCount = [self.us_tableView numberOfRowsInSection:section];
    if (rowCount == 0) return;

    // 获取该 section 的最后一个 indexPath
    NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:rowCount - 1 inSection:section];
    CGRect lastCellRect = [self.us_tableView rectForRowAtIndexPath:lastIndexPath];
    CGRect rectInView = [self.us_tableView convertRect:lastCellRect toView:self.view];

    // 计算键盘顶端 y
    CGFloat keyboardTop = self.view.bounds.size.height - keyboardHeight - toolHeight;
    CGFloat lastCellBottomY = CGRectGetMaxY(rectInView);

    // 设置 contentInset
    UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, keyboardHeight + toolHeight, 0);
    self.us_tableView.contentInset = insets;
    self.us_tableView.scrollIndicatorInsets = insets;

    // 如果 cell 会被遮住就滚动
    if (lastCellBottomY > keyboardTop) {
        CGFloat offset = lastCellBottomY - keyboardTop;
        [self.us_tableView setContentOffset:CGPointMake(0, self.us_tableView.contentOffset.y + offset) animated:YES];
    }
}

- (void)keyboardWillHide:(NSNotification *)notification {

    NSDictionary *info = notification.userInfo;
    NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    [UIView animateWithDuration:duration animations:^{
        self.commentTool.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 74);
    } completion:^(BOOL finished) {
        self.commentTool.hidden = YES;
    }];
    
    UIEdgeInsets insets = UIEdgeInsetsZero;
    self.us_tableView.contentInset = insets;
    self.us_tableView.scrollIndicatorInsets = insets;
}
- (USCommentInputToolView *)commentTool {
    if (_commentTool == nil) {
        _commentTool = [[USCommentInputToolView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 74)];
        _commentTool.hidden = YES;
        _commentTool.textField.placeholder = @"发表评论：";
        @weakify(self)
        _commentTool.onSend = ^(NSString *text) {
            @strongify(self)
            NSLog(@"发送内容: %@", text);
            [self.commentTool.textField resignFirstResponder];
            
            NSString *content = self.commentTool.textField.text?:@"";
            
            self.commentTool.textField.text = @"";
            [self sendComment:content];

        };
        
    }
    return _commentTool;
}

- (void)setupRefresh {
    
    self.currentPage = 1;
    self.pageSize = 15;
    
    @weakify(self)
    self.us_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
     @strongify(self)
        self.currentPage = 1;
        [self updateMomentList];
    }];
    
    self.us_tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        @strongify(self)
        if (self.hasMore) {
            self.currentPage += 1;
            [self updateMomentList];
        } else {
            [self.us_tableView.mj_footer endRefreshingWithNoMoreData];
        }
    }];
}
- (void)updateMomentList{
    NSDictionary *params = @{ @"current": @(self.currentPage),
                              @"size": @(self.pageSize),
                              @"type":@(self.type)
    };

    [[EMNetWork shareManager] em_post:MoodDiaryListPage
                               params:params
                                  hud:nil
                            showError:YES
                              success:^(EMApiModel *api) {
        
        if (!api.success) {
            [self loadingFailed];
            return;
        }
        
        if (self.currentPage == 1) {
            [self.list removeAllObjects];
        }
        
        NSArray *records = [USMomentsModel mj_objectArrayWithKeyValuesArray:api.data[@"totalMoodDiaryList"][@"records"]];
        
        for (USMomentsModel *model in records) {
            model.moodDiaryCommentList = [[model.moodDiaryCommentList reverseObjectEnumerator] allObjects];//倒序
        }
        [self.list addObjectsFromArray:records];
      
        
        // 是否还有更多
        self.hasMore = records.count == self.pageSize;
        
        // 结束刷新状态
        [self.us_tableView.mj_header endRefreshing];
        [self.us_tableView.mj_footer endRefreshing];
        
        if (!self.hasMore) {
            [self.us_tableView.mj_footer endRefreshingWithNoMoreData];
        } else {
            [self.us_tableView.mj_footer resetNoMoreData];
        }
        
        if (self.list.count == 0) {
            self.dataState = EmptyDataStateNoData;
        }
        self.us_tableView.mj_footer.hidden = self.list.count == 0;

        [self.us_tableView reloadData];
        [self.us_tableView reloadEmptyDataSet];
       
    } fail:^{
        
 
    }];
    
    
}
/// 添加评论
/// - Parameters:
///   - content: 内容
- (void)sendComment:(NSString *)content{
 
    USMomentsModel *model = self.list[self.commentIndexPath.section];

    NSDictionary *params = @{ @"content": content,
                              @"moodDiaryId": model.moodDiaryDto.moodDiaryId?:@"",
    };

    @weakify(self)
    [[EMNetWork shareManager] em_post:MoodDiaryCommentAdd
                               params:params
                                  hud:nil
                            showError:NO
                              success:^(EMApiModel *api) {
        @strongify(self)
        if (!api.success) {
            return;
        }
        
      
        USMomentCommentModel *model = [USMomentCommentModel mj_objectWithKeyValues:api.data[@"moodDiaryComment"]];
       
        NSMutableArray *commentList = [NSMutableArray arrayWithArray:self.list[self.commentIndexPath.section].moodDiaryCommentList];
        [commentList insertObject:model atIndex:0];
        self.list[self.commentIndexPath.section].moodDiaryCommentList = commentList;
        
        if (self.list[self.commentIndexPath.section].moodDiaryCommentList.count > 0) {
 
            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:self.commentIndexPath.section];
            [self.us_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
         }
     
    } fail:^{
        
        
    }];
}
  
- (NSMutableArray <USMomentsModel *>*)list {
    if (_list == nil) {
        _list = [NSMutableArray array];
    }
    return _list;
}
- (void)changeType:(UIView *)sender{
    
    @weakify(self)
    DTItem *takePhoto = [DTItem itemWithTitle:@"我的" image:nil tag:0 identifier:nil handle:^(DTItem *item) {
        @strongify(self)
        [self changeTypeAction:2];
    }];
    
    DTItem *choosePhoto = [DTItem itemWithTitle:@"Ta的" image:nil tag:0 identifier:nil handle:^(DTItem *item) {
        @strongify(self)
        [self changeTypeAction:3];

    }];
    DTItem *share = [DTItem itemWithTitle:@"我们的 " image:nil tag:0 identifier:nil handle:^(DTItem *item) {
        @strongify(self)
        [self changeTypeAction:1];
    }];
    
    DTTargetView *targetView = [[DTTargetView alloc]initWithTargetView:sender item:@[takePhoto,choosePhoto,share]];
    [targetView show];

}

- (void)changeTypeAction:(NSInteger)type {
    if (self.type == type) {
        return;
    }
    self.type = type;
    self.currentPage = 1;
    [self.us_tableView.mj_header beginRefreshing];
    
    UIButton *titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    if (type == 1) {
        [titleBtn setTitle:@"我们的日记" forState:0];
    }else if (type == 2) {
        [titleBtn setTitle:@"我的日记" forState:0];
    }else if (type == 3) {
        [titleBtn setTitle:@"Ta的日记" forState:0];
    }
    [titleBtn setTitleColor:UIColor.labelColor forState:0];
    [titleBtn.titleLabel setFont:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium]];
    [titleBtn setImage:[UIImage imageNamed:@"arrow_down"] forState:0];
    titleBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
    [titleBtn addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = titleBtn;
}
- (void)editAction:(UIButton *)sender{

    USMomentsModel *model;
    for (USMomentsModel *eachModel in self.list) {
        if ([eachModel.moodDiaryDto.moodDiaryId intValue] == sender.tag) {
            model = eachModel;
            break;
        }
    }
    if (!model) {
        return;
    }
    @weakify(self)
    DTItem *item0 = [DTItem itemWithTitle:@"编辑" image:[UIImage imageNamed:@"icon-edit-22"] tag:0 identifier:nil handle:^(DTItem *item) {
        @strongify(self)
        [self editMomnt:model];
    }];
    DTItem *item1 = [DTItem itemWithTitle:@"删除" image:[UIImage imageNamed:@"icon-trash-22"] tag:0 identifier:nil handle:^(DTItem *item) {
        @strongify(self)
        [self deleteMomnt:model];
    }];

    
  
    DTTargetView *view = [[DTTargetView alloc]initWithTargetView:sender item:@[item0,item1]];

    [view show];
    
}
- (void)editMomnt:(USMomentsModel *)model{
    USMomentsAddController *vc = [[USMomentsAddController alloc]init];
    vc.momentModel = model;
    vc.isEdit = YES;
    @ weakify(self)
    vc.editMomentBlock = ^(USMomentsModel * _Nonnull momntModel) {
        @strongify(self)
        dispatch_async(dispatch_get_main_queue(), ^{
            NSIndexPath *currentIndexPath = [self.list indexOfObject:momntModel] != NSNotFound ? [NSIndexPath indexPathForRow:0 inSection:[self.list indexOfObject:momntModel]] : nil;
            if (currentIndexPath) {
                NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:currentIndexPath.section];
                [self.us_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
            }
        });
 
    };
    [self.navigationController presentViewController:[[DTNavigationController alloc]initWithRootViewController:vc] animated:YES completion:nil];

}
- (void)deleteMomnt:(USMomentsModel *)model{
    
    MOAlertBaseView *alert = [[MOAlertBaseView alloc]initWithTitle:@"确定删除此记录吗" detailTitle:@"此操作不可撤销哦，请谨慎操作" contentView:nil leftButtonImageName:nil rightButtonImageName:nil autoDissmiss:YES tapDissmiss:YES];
    alert.titleLabel.textColor = UIColor.us_redColor;
    @weakify(self)
    alert.didClickIndexBlock = ^(NSInteger index) {
        @strongify(self)
        if (index == 1) {
            [self requestDelete:model];
        }
    };
    
    [alert show];
    
}
- (void)requestDelete:(USMomentsModel *)model{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
 
    params[@"moodDiaryId"] = model.moodDiaryDto.moodDiaryId?:@"";
 
    NSLog(@"params = %@",params);
    [[EMNetWork shareManager] em_post:MoodDiaryDelete
                               params:params
                                  hud:nil
                           showError:YES
                              success:^(EMApiModel *api) {

        if (!api.success) {
            return;
        }
        
        [USFeedbackTool notifySuccess];
 
        NSIndexPath *currentIndexPath = [self.list indexOfObject:model] != NSNotFound ? [NSIndexPath indexPathForRow:0 inSection:[self.list indexOfObject:model]] : nil;
        if (currentIndexPath) {
            [self.list removeObjectAtIndex:currentIndexPath.section];
            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:currentIndexPath.section];
            [self.us_tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }
    } fail:^{
        
 
    }];
    
}

#pragma mark - action
- (void)addAction{
    [USFeedbackTool impactSoft];
    
    USMomentsAddController *vc = [[USMomentsAddController alloc]init];
    vc.addMomentBlock = ^(USMomentsModel * _Nonnull momntModel) {
        [self.list insertObject:momntModel atIndex:0];

        NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0];
        [self.us_tableView beginUpdates];
        [self.us_tableView insertSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.us_tableView endUpdates];

    };
    [self.navigationController presentViewController:[[DTNavigationController alloc]initWithRootViewController:vc] animated:YES completion:nil];

}
 
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    USMomentsModel *model = self.list[indexPath.section];

    USMomentsDetailController *vc = [[USMomentsDetailController alloc]init];
    vc.momentModel = model;
    @weakify(self)
    vc.deleteMomentBlock = ^{
        @strongify(self)
        
        NSIndexPath *currentIndexPath = [self.list indexOfObject:model] != NSNotFound ? [NSIndexPath indexPathForRow:0 inSection:[self.list indexOfObject:model]] : nil;
        if (currentIndexPath) {
            [self.list removeObjectAtIndex:currentIndexPath.section];
            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:currentIndexPath.section];
            [self.us_tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }
        
    };
    
    vc.editCommentBlock = ^{
      @strongify(self)
        NSIndexPath *currentIndexPath = [self.list indexOfObject:model] != NSNotFound ? [NSIndexPath indexPathForRow:0 inSection:[self.list indexOfObject:model]] : nil;
        if (currentIndexPath) {
            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:currentIndexPath.section];
            [self.us_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }
        
    };
    
    vc.editMomentBlock = ^{
        @strongify(self)
        NSIndexPath *currentIndexPath = [self.list indexOfObject:model] != NSNotFound ? [NSIndexPath indexPathForRow:0 inSection:[self.list indexOfObject:model]] : nil;
        if (currentIndexPath) {
            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:currentIndexPath.section];
            [self.us_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }
    };
    [self.navigationController pushViewController:vc animated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.list.count;

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1 + MIN(2, self.list[section].moodDiaryCommentList.count) + 1;//列表最多显示两条评论
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        USMomentsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"USMomentsCell"];
        cell.breakMode = YES;

        USMomentsModel *model = self.list[indexPath.section];
        cell.model = model;
        cell.editBtn.tag = [model.moodDiaryDto.moodDiaryId intValue];
        [cell.editBtn addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside];
        @weakify(self)
        cell.commentBlock = ^{
            @strongify(self)
            self.commentIndexPath = indexPath;
            [USFeedbackTool impactSoft];
            self.commentTool.hidden = NO;
            [self.commentTool.textField becomeFirstResponder];
        };
        cell.photoPreviewBlock = ^(NSInteger index) {
            @strongify(self)
            USPhotoPreviewController *vc = [[USPhotoPreviewController alloc] init];
            vc.items = model.photoList;
            vc.currentIndex = index;
            [self.navigationController presentViewController:vc animated:YES completion:nil];

        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if(indexPath.row == MIN(2, self.list[indexPath.section].moodDiaryCommentList.count) + 1){
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
        UIImageView *imgView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"lineVector"]];
        [cell.contentView addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(20);
            make.bottom.mas_equalTo(0);
            make.left.mas_equalTo(16);
            make.right.mas_equalTo(-16);
            make.height.mas_equalTo(2.5);
        }];
        cell.backgroundColor = UIColor.clearColor;
        cell.contentView.backgroundColor = UIColor.clearColor;
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else {
        USMomentCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"USMomentCommentCell"];
        cell.breakMode = 1;
        cell.model = self.list[indexPath.section].moodDiaryCommentList[indexPath.row - 1];
        if (self.list[indexPath.section].moodDiaryCommentList.count >= 2 && indexPath.row == 1) {
            cell.lineView.hidden =  NO;
        }else{
            cell.lineView.hidden = YES;
        }

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }

}
//-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//    if (indexPath.row > 0) {
//        USMomentCommentCell *commentCell = (USMomentCommentCell *)cell;
//
//        if (self.list[indexPath.section].moodDiaryCommentList.count == 1) {
//            [commentCell.bgView jk_setRoundedCorners:UIRectCornerAllCorners radius:14];
//        }else{
//            if (indexPath.row == 1) {
//                [commentCell.bgView jk_setRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:14];
//            }else if (indexPath.row == 2){
//                [commentCell.bgView jk_setRoundedCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:14];
//            }
//        }
//
//    }
// 
//}
 
#pragma mark - DZNEmptyDataSetSource,DZNEmptyDataSetDelegate

- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView{
    
//    if (self.dataState == EmptyDataStateLoading) {
//        UIView *contentView = [UIView new];
//        contentView.frame = CGRectMake(0, 0, self.view.jk_width, 200);
//
//        NSString *gifPath = [[NSBundle mainBundle] pathForResource:@"load_page" ofType:@"gif"];
//        UIImageView *imageView = [[UIImageView alloc] initWithImage:nil];
//        imageView.contentMode = UIViewContentModeScaleAspectFit;
//        imageView.frame = CGRectMake(0, 0, 200, 200);
//        [imageView sd_setImageWithURL:[NSURL fileURLWithPath:gifPath]];
//
//        [contentView addSubview:imageView];
//        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.width.height.mas_equalTo(200);
//            make.center.mas_equalTo(contentView);
//        }];
//
//        return contentView;
//    }
    if (self.dataState == EmptyDataStateNoData) {
        USEmptyView *emptyView = [[USEmptyView alloc] initWithFrame:CGRectMake(0, 0, self.view.jk_width, 0)];
        emptyView.image = [UIImage imageNamed:@"Frame 114"];
        emptyView.title = @"还没有日记哦\n～我们一起写日记吧～";
        emptyView.btnTitle = @"写日记";
        emptyView.userInteractionEnabled = YES;
        [emptyView.btn addTarget:self action:@selector(addAction) forControlEvents:UIControlEventTouchUpInside];
        return emptyView;
    }
   
    return nil;
    
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    
    
    return YES; // 允许点击
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    
    
    return YES; // 避免 scrollView 吃掉 touch 事件
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
